package com.hps.shiro.config;

import com.hps.shiro.auth.Oauth2Filter;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author heps
 * @since 2020/6/8 19:20
 */
@Configuration
public class ShiroConfig {

  @Value("${userInfoUrl}")
  private String userInfoUrl;

  @Bean
  FilterRegistrationBean<Filter> shiroFilterRegistrationBean() {
    FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
    bean.setFilter(new Oauth2Filter(userInfoUrl));
    bean.addUrlPatterns("/*");
    return bean;
  }
}
